package com.ogawa.a7517.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ogawa.a7517.R;
import com.ogawa.a7517.bean.DeviceStateBean;
import com.ogawa.a7517.bean.MassageArmchair;

public class GasView extends FrameLayout {
    private ImageView ivShoulder, ivHandLeft, ivHandRight, ivHipLeft, ivHipRight, ivLeg, ivFoot;

    public GasView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public GasView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public GasView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.layout_gas_view, this);
        ivShoulder = findViewById(R.id.iv_gas_shoulder);
        ivHandLeft = findViewById(R.id.iv_gas_hand_left);
        ivHandRight = findViewById(R.id.iv_gas_hand_right);
        ivHipLeft = findViewById(R.id.iv_gas_hip_left);
        ivHipRight = findViewById(R.id.iv_gas_hip_right);
        ivLeg = findViewById(R.id.iv_gas_leg);
        ivFoot = findViewById(R.id.iv_gas_foot);
    }

    public void deviceStateChange() {
        DeviceStateBean deviceStatusBean = MassageArmchair.getInstance().getDeviceStatusBean();
        DeviceStateBean.FunctionsBean.AirCellShoulderStatusBean airCellShoulderStatus
                = deviceStatusBean.getFunctions().getAirCellShoulderStatus();
        if (airCellShoulderStatus != null) {
            int shoulder = Integer.parseInt(airCellShoulderStatus.getModelValue());
            ivShoulder.setVisibility(shoulder == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCelllegStatusBean airCelllegStatus
                = deviceStatusBean.getFunctions().getAirCelllegStatus();
        if (airCelllegStatus != null) {
            int leg = Integer.parseInt(airCelllegStatus.getModelValue());
            ivLeg.setVisibility(leg == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCellFootStatusBean airCellFootStatus
                = deviceStatusBean.getFunctions().getAirCellFootStatus();
        if (airCellFootStatus != null) {
            int foot = Integer.parseInt(airCellFootStatus.getModelValue());
            ivFoot.setVisibility(foot == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCellHandLeftStatusBean airCellHandLeftStatus
                = deviceStatusBean.getFunctions().getAirCellHandLeftStatus();
        if (airCellHandLeftStatus != null) {
            int handLeft = Integer.parseInt(airCellHandLeftStatus.getModelValue());
            ivHandLeft.setVisibility(handLeft == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCellHandRightStatusBean airCellHandRightStatus
                = deviceStatusBean.getFunctions().getAirCellHandRightStatus();
        if (airCellHandRightStatus != null) {
            int handRight = Integer.parseInt(airCellHandRightStatus.getModelValue());
            ivHandRight.setVisibility(handRight == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCellSeatLeftBean airCellSeatLeft
                = deviceStatusBean.getFunctions().getAirCellSeatLeft();
        if (airCellSeatLeft != null) {
            int seatLeft = Integer.parseInt(airCellSeatLeft.getModelValue());
            ivHipLeft.setVisibility(seatLeft == 1 ? VISIBLE : GONE);
        }
        DeviceStateBean.FunctionsBean.AirCellSeatRightBean airCellSeatRight
                = deviceStatusBean.getFunctions().getAirCellSeatRight();
        if (airCellSeatRight != null) {
            int seatRight = Integer.parseInt(airCellSeatRight.getModelValue());
            ivHipRight.setVisibility(seatRight == 1 ? VISIBLE : GONE);
        }
    }

    public void stateReset() {
        ivShoulder.setVisibility(GONE);
        ivHandLeft.setVisibility(GONE);
        ivHandRight.setVisibility(GONE);
        ivHipLeft.setVisibility(GONE);
        ivHipRight.setVisibility(GONE);
        ivLeg.setVisibility(GONE);
        ivFoot.setVisibility(GONE);
    }

}
